
const app = getApp();
import { VenueScCode, VenueScNumber } from "../../../api/my"
import { getStorage } from "../../../utils/localStorage"
import { baseUrl } from "../../../api/request"
Page({
    data: {
        navData: {
            level: 2,
            title: "核销扫码"
        },
        imgUrl: baseUrl,
        navMargin: app.globalData.navHeight + app.globalData.navTop,
        infoData: {},
        scene: {
            id: null,
            userId: null,
            couponCodeId: null
        },
        state: null, //扫码结果
        msg: null, //扫码结果提示
        couponCodeNumber: null, //核销码
    },
    onLoad(options) {
        let scene = decodeURIComponent(options.scene);
        this.setData({
            imgUrl: baseUrl,
            "scene.couponCodeId": scene.substring(scene.indexOf("=") + 1, scene.indexOf("&")),
            "scene.userId": scene.substring(scene.lastIndexOf("=") + 1, scene.length),
            "scene.id": getStorage('user').id
        });
        this.getVenueScCode();
    },
    //获取扫码结果数据
    getVenueScCode() {
        VenueScCode(this.data.scene).then(res => {
            if (res.data.code === 200) {
                this.setData({
                    state: 1,
                    infoData: res.data.data,
                    msg: res.data.msg
                });
            } else {
                this.setData({
                    state: 2,
                    infoData: res.data.data,
                    msg: res.data.msg
                });
            };
        });
    },
    //请输入签到码input框input事件
    activedM(e) {
        this.setData({
            couponCodeNumber: e.detail.value
        });
    },
    //核销按钮操作事件
    submit() {
        if (!this.data.couponCodeNumber) {
            wx.showToast({
                icon: "none",
                title: "请输入核销码",
            });
        }
        VenueScNumber({ couponCodeNumber: this.data.couponCodeNumber, userId: this.data.scene.id }).then(res => {
            if (res.data.code === 200) {
                this.setData({
                    state: 1,
                    infoData: res.data.data,
                    msg: res.data.msg
                });
            } else {
                this.setData({
                    state: 2,
                    infoData: res.data.data,
                    msg: res.data.msg
                });
            };
        })
    },
    //左上角返回箭头事件
    back(){
        console.log(123);
    },
    onReady() {

    },
    onShow() {

    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})